package com.velpro.im.controller.handle;

import com.velpro.im.controller.base.Result;
import com.velpro.im.service.common.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.jws.WebResult;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Service;

@ControllerAdvice
public class GlobalControllerExceptionHandle {

    private  final Logger logger = LoggerFactory.getLogger(GlobalControllerExceptionHandle.class);

    @ResponseBody
    @ExceptionHandler(ServiceException.class)
    public Result serviceException(HttpServletResponse response, ServiceException ex){
        return Result.error(ex.getMessage());
    }

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Result Exception(HttpServletResponse response, Exception ex){
        logger.error("系统异常",ex);
        return Result.fail();
    }

}
